
(function reg(){
	var openId = getQueryParamValue("openId");
	var userId = getQueryParamValue("userId");
	var result = getCookie("WECHAT_USER_OPENID");
	var result2 = getCookie("WECHAT_USER_USERID");
	if (result == null) {
		setCookie("WECHAT_USER_OPENID", openId);
	}
	if (result2 == null) {
		setCookie("WECHAT_USER_USERID", userId);
	}
})()


//js获取项目根路径
function getRootPath(){  
    var currentPath=window.document.location.href;  
    var pathName=window.document.location.pathname;  
    var pos=currentPath.indexOf(pathName);  
    var localhostPaht=currentPath.substring(0,pos);  
//    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);  
    return(localhostPaht+"/wx");  
}

//获取请求参数
function getQueryParamValue(key) {
	var uri = window.location.search;
	var reg = new RegExp("" + key + "=([^&?]*)", "ig");
	return (uri.match(reg)) ? (uri.match(reg)[0].substr(key.length + 1)) : null;
}

//空值转换
function emptyValConvert(val){
	if(val!=undefined && val!=''){
		return val;
	}else{
		return '';
	}
}

//配置值替换
function packageValReplace(val){
	if(val=='有'){
		return '●';
	}else if(val=='无'){
		return '-';
	}else if(val=='选配'){
		return '○';
	}else{
		return emptyValConvert(val);
	}
	
}
function getCookie(cookie_name) {
	var allcookies = document.cookie;
	var cookie_pos = allcookies.indexOf(cookie_name);

	// 如果找到了索引，就代表cookie存在，
	// 反之，就说明不存在。
	if (cookie_pos != -1) {
		// 把cookie_pos放在值的开始，只要给值加1即可。
		cookie_pos += cookie_name.length + 1;
		var cookie_end = allcookies.indexOf(";", cookie_pos);

		if (cookie_end == -1) {
			cookie_end = allcookies.length;
		}

		var value = unescape(allcookies.substring(cookie_pos, cookie_end));
	}

	return value;
}
function setCookie(name,value)
{
    var Days = 1;
    var exp  = new Date(); 
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+";path=/";
	// alert(document.cookie);
}
